package On_class.L0415;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Jdbc {

    public static void main(String[] args) throws Exception {
        String url="jdbc:mysql://localhost:3306/jdbc?serverTimezone=GMT%2B8";
        String user="root";
        String password="2001hong";
        Connection conn = DriverManager.getConnection(url,user,password);

        String sql1="update user set name='lucy' where id=2";
        String sql2="select * from user";

        Statement stmt=conn.createStatement();
        int i=stmt.executeUpdate(sql1);
        System.out.println(i);
        System.out.println("-------");
        ResultSet rs=stmt.executeQuery(sql2);
        System.out.println("查询结果：");
        while (rs.next()){
            int id=rs.getInt("id");
            String name=rs.getString("name");
            System.out.println(id+"\t"+name);
        }

        stmt.close();
        conn.close();
    }
}
